package lab.exec;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import cn.flant.io.IOUtil;

public class TestEms {

	static class EmsItem extends BalanceItem {

		int emsId;
		int size;

		public EmsItem(int emsId, int size) {
			this.emsId = emsId;
			this.size = size;
		}

		@Override
		public int getSize() {
			return size;
		}

		public String toString() {
			return String.valueOf(emsId);
		}
	}

	private static int sum(BalanceItem[] items) {
		int sum = 0;
		for (BalanceItem item : items) {
			sum += item.getSize();
		}
		return sum;
	}

	public static void main(String[] args) throws Exception {
		Properties prop = new Properties();
		FileInputStream in = new FileInputStream("temp.ini");
		prop.load(in);
		IOUtil.close(in);
		Set<String> keySet = prop.stringPropertyNames();
		List<EmsItem> items = new ArrayList<EmsItem>();
		for (String key : keySet) {
			EmsItem item = new EmsItem(Integer.valueOf(key), Integer.valueOf(prop.getProperty(key)));
			items.add(item);
		}
		EmsItem[] array = items.toArray(new EmsItem[keySet.size()]);
		BalanceExecutor sb = new RollBalance();
		BalanceItem[][] result = (BalanceItem[][]) sb.balance(array, 10);
		for (BalanceItem[] ia : result) {
			System.out.println("[" + sum(ia) + "]: " + Arrays.toString(ia));
		}

	}
}
